home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / setjmp / test.c < prev   
C/C++ Source or Header  |  1992-03-12  |  471b  |  44 lines

  1. /* 
  2.  * Test program to verify that setjmp and longjmp work.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <setjmp.h>
  7.  
  8. jmp_buf env;
  9.  
  10. main()
  11. {
  12.     int ch;
  13.  
  14.     for (;;) {
  15.     if (setjmp(env)) {
  16.         printf("longjmp.\n");
  17.     }
  18.     printf("? ");
  19.     ch = getone();
  20.     if (ch == EOF) {
  21.         exit(0);
  22.     } else {
  23.         printf("%c\n", ch);
  24.     }
  25.     }
  26. }
  27.  
  28. getone()
  29. {
  30.     return getone_b();
  31. }
  32.  
  33. getone_b()
  34. {
  35.     int ch;
  36.  
  37.     ch = getchar();
  38.     if (ch == 'l') {
  39.     longjmp(env, 1);
  40.     } else {
  41.     return ch;
  42.     }
  43. }
  44.